import { IPSDataEntity } from '../ipsdata-entity';
import { IPSDEFSearchMode } from '../defield/ipsdefsearch-mode';
import { IPSDEField } from '../defield/ipsdefield';
import { IPSDEDataSetInputDTOField } from './ipsdedata-set-input-dtofield';
import { IPSDEFilterDTOField } from './ipsdefilter-dtofield';
import { PSDEMethodDTOFieldImpl } from '../service/psdemethod-dtofield-impl';

export class PSDEFilterDTOFieldImpl extends PSDEMethodDTOFieldImpl implements IPSDEFilterDTOField, IPSDEDataSetInputDTOField {
  protected psdefsearchmode: IPSDEFSearchMode | null = null;

  getPSDEFSearchMode(): IPSDEFSearchMode | null {
    if (this.psdefsearchmode != null) return this.psdefsearchmode;
    const value = this.M.getPSDEFSearchMode;
    if (value == null) {
      return null;
    }
    const ipsdefield = this.getPSDEField();
    if (ipsdefield != null) {
      this.psdefsearchmode = ipsdefield.findPSDEFSearchMode(value);
    }
    return this.psdefsearchmode;
  }

  get psDEFSearchMode(): IPSDEFSearchMode | null {
    return this.getPSDEFSearchMode();
  }

  getPSDEFSearchModeMust(): IPSDEFSearchMode {
    const value = this.getPSDEFSearchMode();
    if (value == null) {
      throw new Error('未指定实体属性搜索模式');
    }
    return value;
  }

  protected psdefield: IPSDEField | null = null;

  getPSDEField(): IPSDEField | null {
    if (this.psdefield != null) return this.psdefield;
    const value = this.M.getPSDEField;
    if (value == null) {
      return null;
    }
    const ipsdataentity = this.getParentPSModelObject('dataentity.IPSDataEntity') as IPSDataEntity;
    if (ipsdataentity != null) {
      this.psdefield = ipsdataentity.findPSDEField(value);
    }
    return this.psdefield;
  }

  get psDEField(): IPSDEField | null {
    return this.getPSDEField();
  }

  getPSDEFieldMust(): IPSDEField {
    const value = this.getPSDEField();
    if (value == null) {
      throw new Error('未指定实体属性');
    }
    return value;
  }

  get cls(): string {
    return 'PSDEFilterDTOFieldImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'dataentity.ds.IPSDEDataSetInputDTOField' || cls == 'dataentity.ds.IPSDEFilterDTOField') return true;
    return super.instanceof(cls);
  }
}
